package com.weex.app.extend;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.WXModule;
import com.weex.app.WxPageActivity;


/**
 * @author kalaqia 421407393@qq.com
 */
public class WXEventModule extends WXModule {
    @JSMethod()
    public void openURL(String url) {
        if (TextUtils.isEmpty(url)) {
            return;
        }
        Uri uri = Uri.parse(url);
        String scheme = uri.getScheme();

        if ("http".equals(scheme) || "https".equals(scheme) || "file".equals(scheme)) {
            Intent renderIntent = new Intent(mWXSDKInstance.getContext(), WxPageActivity.class);
            renderIntent.setData(uri);
            mWXSDKInstance.getContext().startActivity(renderIntent);
        } else {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(uri);
            mWXSDKInstance.getContext().startActivity(intent);
        }
    }
}
